

import Foundation
import os.log

class SystemConsoleLogger: Logger {

    static let general = OSLog(subsystem: "net.measurementlab.NDT7", category: "ndt7")

    func addLogMessage(_ logMessage: LogMessage) {
        os_log("[%{public}@] [%{public}@-%{public}@:%{public}@] (%{public}@) %{public}@",
               log: SystemConsoleLogger.general,
               type: osLogLevel(logMessage.level),
               queueName() ?? "",
               logMessage.file,
               logMessage.function,
               String(logMessage.line),
               logMessage.level.rawValue,
               logMessage.text
               )
    }

    func osLogLevel(_ logLevel: LogLevel) -> OSLogType {

        switch logLevel {
        case .info:
            return .info
        case .debug:
            return .debug
        case .warning:
            return .error
        case .error:
            return .fault
        }
    }
}
